package com.shenzhenai.composebasic.components

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.material3.Card
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp

/**
 * @author huangzehui
 * @date 14/9/2025 下午7:54 周日
 * @description
 *
 * LazyVerticalGrid 用法
 * https://www.bilibili.com/video/BV1Mi4y117io?vd_source=e07cc8cc94eb22bd76722071b03cd199&spm_id_from=333.788.videopod.sections
 *
 */
@Composable
fun LazyVerticalGridSample() {
    val data = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)

//    LazyVerticalGrid(
//        columns = GridCells
//            // 设置网格是固定多少列
//            .Fixed(
//                // 设置item是3列
//                count = 3
//            ),
//        // 当前网格容器的内边距
//        contentPadding = PaddingValues(10.dp)
//    ) {
//        items(data.size) {
//            Card {
//                Text(text = "Grid Item ${it}", modifier = Modifier.padding(8.dp))
//            }
//        }
//    }

    LazyVerticalGrid(
        columns = GridCells.Adaptive(
            //  每一列的宽度为固定50dp
            50.dp
        ),
        // 当前网格容器的内边距
        contentPadding = PaddingValues(10.dp)
    ) {
        items(data.size) {
            Card {
                Text(text = "Grid Item ${it}", modifier = Modifier.padding(8.dp))
            }
        }
    }

}

@Preview
@Composable
fun LazyVerticalGridSamplePreview() {
    LazyVerticalGridSample()
}